﻿package{
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.render.BasicRenderEngine;

	public class Test extends MovieClip {
		private var _viewport:Viewport3D;
		private var _scene:Scene3D;
		private var _camera:Camera3D;
		private var _renderEngine:BasicRenderEngine;
		private var _light:PointLight3D;
		
		public var colorMaterial:ColorMaterial;
		public var plane:Plane;
		
		public function Test():void {
				
			_viewport = new Viewport3D(0, 0, true, true);
			_viewport.buttonMode = true;
			this.addChild(_viewport);
			
			_scene = new Scene3D();
			
			_camera = new Camera3D();
			
			_renderEngine = new BasicRenderEngine();
			
			colorMaterial = new ColorMaterial(0x333333,1,true);
			
			plane = new Plane(colorMaterial, 300, 300, 6, 6);
			plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, _clickHandler);
			_scene.addChild(plane);
			
			this.addEventListener(Event.ENTER_FRAME, _enterFrameHandler);
			
		}
		
		private function _clickHandler(e:InteractiveScene3DEvent):void {
			//trace('click');
			_scene.removeChild(plane);
		}
		
		
		private function _enterFrameHandler(e:Event):void {
			_renderEngine.renderScene(_scene, _camera, _viewport);
		}
	}
}

